package cn.yj.alipay;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author 永健
 * @since 2022-01-21 16:26
 */
public class EnableAliPayCondition implements Condition {

    private static final Logger log = LoggerFactory.getLogger(EnableAliPayCondition.class);

    /**
     * 默认开启盲盒支付
     */
    private static final boolean START_PAY = false;
    private static final String ALIPAY_START_KEY = "pay.alipay.start";
    private static final String PAY_START_KEY = "pay.start";

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        Environment environment = conditionContext.getEnvironment();
        Boolean startPay = Boolean.valueOf(environment.getProperty(PAY_START_KEY, String.valueOf(START_PAY)));
        Boolean aBoolean = Boolean.valueOf(environment.getProperty(ALIPAY_START_KEY, String.valueOf(START_PAY)));
        log.info("是否启支付宝支付={}",startPay,aBoolean);
        return aBoolean && startPay;
    }
}
